home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0709.dms / q0709.adf / Graphics / Fonts / Example4.c < prev    next >
C/C++ Source or Header  |  1992-07-29  |  9KB  |  267 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Graphics                Amiga C Club       */
  7. /* Chapter: Fonts                       Tulevagen 22       */
  8. /* File:    Example4.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-04-28                                       */
  11. /* Version: 1.00                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example opens disk fonts and prints some interesting */
  21. /* information about them. (Height, width, flags, style,     */
  22. /* etc...) Syntax: Example4 [font1] [font2] [font3] ...      */
  23. /* (The largest size of each font will be used.)             */
  24.  
  25.  
  26.  
  27. #include <intuition/intuitionbase.h>
  28.  
  29.  
  30. struct Intuition *IntuitionBase; /* Running under Intuition. */
  31. struct GfxBase *GfxBase;         /* Move() and Text().       */
  32. struct Library *DiskfontBase;    /* OpenDiskFont() etc.      */
  33. /* NOTE! If you want to use the functions OpenDiskFont() or  */
  34. /* AvailFonts() you have to open the Diskfont Library!       */
  35.  
  36.  
  37. /* The new font's attributes: */
  38. struct TextAttr my_font_attr=
  39. {
  40.   "",          /* Fontname, will be changed.       */
  41.   100,         /* Largest possible size. (Max 100) */
  42.   FS_NORMAL,   /* Normal style.                    */
  43.   FPF_DISKFONT /* Exist on Disk.                   */
  44. };
  45.  
  46. /* Pointer to our new font: */
  47. struct TextFont *my_font;
  48.  
  49.  
  50. /* Declare a pointer to a Window structure: */ 
  51. struct Window *my_window;
  52.  
  53. /* Declare and initialize your NewWindow structure: */
  54. struct NewWindow my_new_window=
  55. {
  56.   0,             /* LeftEdge    x position of the window. */
  57.   12,            /* TopEdge     y positio of the window. */
  58.   640,           /* Width       640 pixels wide. */
  59.   100,           /* Height      100 lines high. */
  60.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  61.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  62.   CLOSEWINDOW,   /* IDCMPFlags  The window will give us a message if the */
  63.                  /*             user has selected the Close window gad. */
  64.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  65.   WINDOWCLOSE|   /*             Close Gadget. */
  66.   WINDOWDRAG|    /*             Drag gadget. */
  67.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  68.   ACTIVATE,      /*             The window should be Active when opened. */
  69.   NULL,          /* FirstGadget No Custom gadgets. */
  70.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  71.   "Font Test",   /* Title       Title of the window. */
  72.   NULL,          /* Screen      Connected to the Workbench Screen. */
  73.   NULL,          /* BitMap      No Custom BitMap. */
  74.   0,             /* MinWidth    No sizing gadget. */
  75.   0,             /* MinHeight          -"-        */
  76.   0,             /* MaxWidth           -"-        */
  77.   0,             /* MaxHeight          -"-        */
  78.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  79. };
  80.  
  81.  
  82.  
  83. void main();
  84. void clean_up();
  85.  
  86.  
  87. void main( argc, argv )
  88. int argc;
  89. char *argv[];
  90. {
  91.   BOOL close_me;                   /* Used in the loop.                     */
  92.   ULONG class;                     /* IDCMP flag.                           */
  93.   struct IntuiMessage *my_message; /* IntuiMessage structure.               */
  94.   UBYTE count = 1;                 /* Counter.                              */
  95.   char font_name[ 50 ];            /* Font name plus the extension ".font". */
  96.  
  97.  
  98.   /* Open the necessary libraries: */
  99.   IntuitionBase = (struct IntuitionBase *)
  100.     OpenLibrary( "intuition.library", 0 );
  101.   if( !IntuitionBase )
  102.     clean_up( "Could not open Intuition library!" );
  103.  
  104.   GfxBase = (struct GfxBase *)
  105.     OpenLibrary( "graphics.library", 0 );
  106.   if( !GfxBase )
  107.     clean_up( "Could not open Graphics library!" );
  108.  
  109.   DiskfontBase = (struct DiskfontBase *)
  110.     OpenLibrary( "diskfont.library", 0 );
  111.   if( !DiskfontBase )
  112.     clean_up( "Could not open Diskfont library!" );
  113.  
  114.  
  115.   /* Examine font after font... */
  116.   while( count < argc )
  117.   {
  118.     /* Print the name of the font: */
  119.     printf( "\nFont: %s\n", argv[ count ] );
  120.  
  121.     /* Add the extension ".font": */
  122.     strcpy( font_name, argv[ count ] );
  123.     strcat( font_name, ".font" );
  124.  
  125.     /* Set desired font: */
  126.     my_font_attr.ta_Name = font_name;
  127.     
  128.  
  129.     /* Try to open a disk font: */
  130.     my_font = (struct TextFont *)
  131.       OpenDiskFont( &my_font_attr );
  132.  
  133.     /* Have we opened the font successfully? */
  134.     if( !my_font )
  135.       clean_up( "Could not open the font!" );
  136.  
  137.  
  138.     /* Set the height of the window: */
  139.     my_new_window.Height = my_font->tf_YSize + 30;
  140.  
  141.     /* Open a window in which we will display the new font: */
  142.     my_window = (struct Window *) OpenWindow( &my_new_window );
  143.   
  144.     /* Have we opened the window succesfully? */
  145.     if(my_window == NULL)
  146.       clean_up( "Could not open the window!" );
  147.  
  148.  
  149.     /* Set colour and draw mode: */
  150.     SetAPen( my_window->RPort, 1 );
  151.     SetDrMd( my_window->RPort, JAM1 );
  152.  
  153.  
  154.     /* Change the window's default font: */
  155.     SetFont( my_window->RPort, my_font );
  156.  
  157.  
  158.     /* Position the cursor, and print some characters: */
  159.     Move( my_window->RPort, 10, my_font->tf_Baseline + 20 );
  160.     Text( my_window->RPort, "ABCDE abcde", 11 );
  161.  
  162.  
  163.     /* Give the user some information about the font: */
  164.     printf( "YSize:     %d\n", my_font->tf_YSize );
  165.     printf( "XSize:     %d\n", my_font->tf_XSize );
  166.     printf( "Baseline:  %d\n", my_font->tf_Baseline );
  167.     printf( "Accessors: %d\n", my_font->tf_Accessors );
  168.     printf( "LoChar:    %d\n", my_font->tf_LoChar );
  169.     printf( "HiChar:    %d\n", my_font->tf_HiChar );
  170.     printf( "Modulo:    %d\n", my_font->tf_Modulo );
  171.     printf( "Style:\n%s%s%s%s%s",
  172.       my_font->tf_Style & FSF_UNDERLINED ? "  Underlined\n" : "",
  173.       my_font->tf_Style & FSF_BOLD ? "  Bold\n" : "",
  174.       my_font->tf_Style & FSF_ITALIC ? "  Italic\n" : "",
  175.       my_font->tf_Style & FSF_EXTENDED ? "  Extended\n" : "",
  176.       !my_font->tf_Style ? "  Normal\n" : "" );
  177.     printf( "Flags:\n%s%s%s%s%s%s%s",
  178.       my_font->tf_Flags & FPF_ROMFONT ? "  ROM Font\n" : "",
  179.       my_font->tf_Flags & FPF_DISKFONT ? "  Disk Font\n" : "",
  180.       my_font->tf_Flags & FPF_REVPATH ? "  Reversed path\n" : "",
  181.       my_font->tf_Flags & FPF_TALLDOT ? "  Hiresolution, Non-Interlaced\n" : "",
  182.       my_font->tf_Flags & FPF_WIDEDOT ? "  Lowresolution, Interlaced\n" : "",
  183.       my_font->tf_Flags & FPF_PROPORTIONAL ? "  Proportional\n" : "",
  184.       my_font->tf_Flags & FPF_DESIGNED ? "  Designed\n" : "" );
  185.  
  186.  
  187.     /* Wait until the user closes the window: */
  188.     close_me = FALSE;
  189.     while( close_me == FALSE )
  190.     {
  191.       /* Wait until we have recieved a message: */
  192.       Wait( 1 << my_window->UserPort->mp_SigBit );
  193.  
  194.       /* Collect the message: */
  195.       while( (my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort )) )
  196.       {
  197.         /* After we have collected the message we can read it, and save any */
  198.         /* important values which we maybe want to check later: */
  199.         class = my_message->Class;
  200.  
  201.         /* After we have read it we reply as fast as possible: */
  202.         /* REMEMBER! Do never try to read a message after you have replied! */
  203.         /* Some other process has maybe changed it. */
  204.         ReplyMsg( my_message );
  205.  
  206.         /* Check which IDCMP flag was sent: */
  207.         if( class == CLOSEWINDOW )
  208.           close_me=TRUE; /* The user selected the Close window gadget! */  
  209.       }
  210.     }
  211.     
  212.  
  213.     /* Close the font: */
  214.     CloseFont( my_font );
  215.     my_font = NULL;
  216.  
  217.  
  218.     /* Close the window: */
  219.     CloseWindow( my_window );
  220.     my_window = NULL;
  221.  
  222.     count++;
  223.   }
  224.   
  225.   /* No arguments? */
  226.   if( argc == 1 )
  227.   {
  228.     printf( "Which font(s) do you want to examine?\n" );
  229.     printf( "Syntax: Example4 [font1] [font2] [font3] ...\n" );
  230.   }
  231.   
  232.   /* Was it started from Workbench? */
  233.   if( !argc )
  234.   {
  235.     printf( "Sorry, can not be used from Worbench.\n" );
  236.  
  237.     /* Wait 5 seconds: */
  238.     Delay( 5 * 50 );
  239.   }
  240.  
  241.   clean_up( "The End" );
  242. }
  243.  
  244. void clean_up( message )
  245. STRPTR message;
  246. {
  247.   if( my_window )
  248.     CloseWindow( my_window );
  249.  
  250.   if( my_font )
  251.     CloseFont( my_font );
  252.  
  253.   if( DiskfontBase )
  254.     CloseLibrary( DiskfontBase );
  255.  
  256.   if( GfxBase )
  257.     CloseLibrary( GfxBase );
  258.  
  259.   if( IntuitionBase )
  260.     CloseLibrary( IntuitionBase );
  261.   
  262.   printf( "%s\n", message );
  263.  
  264.   exit();
  265. }
  266.  
  267.